﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Automobile.service.BLL;
using Automobile.service.Model;
using System.Data;

namespace Automobile.service.UI
{
    public partial class UpdatePurchase : System.Web.UI.Page
    {
        PurchaseBll bll = new PurchaseBll();
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                if (Request.QueryString["fid"] != null)
                {
                    LoadData();
                }
            }
        }

        private void LoadData()
        {
            this.TextBox1.Text = Request.QueryString["fid"].ToString();

            DataTable dt = bll.GetPurchase(this.TextBox1.Text);
            if (dt != null)
            {
                this.TextBox2.Text= dt.Rows[0][1].ToString();
                this.TextBox3.Text= dt.Rows[0][2].ToString();
                this.TextBox4.Text= dt.Rows[0][3].ToString();
                this.TextBox5.Text= dt.Rows[0][4].ToString();
                this.TextBox6.Text= dt.Rows[0][5].ToString();
                this.TextBox7.Text= dt.Rows[0][6].ToString();
                this.TextBox8.Text= dt.Rows[0][7].ToString();
                this.TextBox9.Text= dt.Rows[0][8].ToString();               
            }
        }

        protected void Button1_Click(object sender, EventArgs e)
        {
            PurchaseModel model = new PurchaseModel();
            model.Purchase_Id= Convert.ToInt32(this.TextBox1.Text);
            model.Purchase_curom = Convert.ToInt32(TextBox2.Text);
            model.Purchase_date= Convert.ToDateTime(TextBox3.Text);
            model.Purchase_State=TextBox4.Text.ToString();
            model.SumMoney = Convert.ToInt32(TextBox5.Text);
            model.Purchase_Remark =TextBox6.Text.ToString();
            model.Supplier_Id = Convert.ToInt32(TextBox7.Text);
            model.WareHose_Id = Convert.ToInt32(TextBox8.Text);
            model.Employee_Id = Convert.ToInt32(TextBox9.Text);
            if (bll.UpdatePurchase(model) > 0)
            {
                Response.Write("<script>alert('库房商品信息修改成功!');location.href='Purchase.aspx';</script>");
            }
        }

        protected void btnBack_Click(object sender, EventArgs e)
        {
            Response.Redirect("Purchase.aspx");
        }
    }
}